#include "CFolderUtils.h"
#include <shlobj_core.h>

#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "Shell32.lib")

#define IMPLEMENT_FOLDER_API(_class, _fun_name) _tstring _class::Get##_fun_name(){return GetKnownFolder(FOLDERID_##_fun_name);}

static _tstring GetKnownFolder(_In_ REFKNOWNFOLDERID rfid)
{
    _tstring strFolder;
    LPWSTR pstr = NULL;
    HRESULT hr = S_OK;
    hr = SHGetKnownFolderPath(rfid, KF_FLAG_DEFAULT, NULL, &pstr);
    if (NULL != pstr)
    {
#ifdef _UNICODE
        strFolder = pstr;
#else
        CHAR szBuf[MAX_PATH] = { 0 };
        int nConverted = ::WideCharToMultiByte(CP_ACP, 0, pstr, -1, szBuf, _countof(szBuf), NULL, NULL);
        if (0 != nConverted)
        {
            strFolder = szBuf;
        }
#endif

        CoTaskMemFree(pstr);
    }

    return strFolder;
}

IMPLEMENT_FOLDER_API(CFolderUtils, NetworkFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, ComputerFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, InternetFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, ControlPanelFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, PrintersFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, SyncManagerFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, SyncSetupFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, ConflictFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, SyncResultsFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, RecycleBinFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, ConnectionsFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, Fonts)
IMPLEMENT_FOLDER_API(CFolderUtils, Desktop)
IMPLEMENT_FOLDER_API(CFolderUtils, Startup)
IMPLEMENT_FOLDER_API(CFolderUtils, Programs)
IMPLEMENT_FOLDER_API(CFolderUtils, StartMenu)
IMPLEMENT_FOLDER_API(CFolderUtils, Recent)
IMPLEMENT_FOLDER_API(CFolderUtils, SendTo)
IMPLEMENT_FOLDER_API(CFolderUtils, Documents)
IMPLEMENT_FOLDER_API(CFolderUtils, Favorites)
IMPLEMENT_FOLDER_API(CFolderUtils, NetHood)
IMPLEMENT_FOLDER_API(CFolderUtils, PrintHood)
IMPLEMENT_FOLDER_API(CFolderUtils, Templates)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonStartup)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonPrograms)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonStartMenu)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicDesktop)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramData)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonTemplates)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicDocuments)
IMPLEMENT_FOLDER_API(CFolderUtils, RoamingAppData)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalAppData)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalAppDataLow)
IMPLEMENT_FOLDER_API(CFolderUtils, InternetCache)
IMPLEMENT_FOLDER_API(CFolderUtils, Cookies)
IMPLEMENT_FOLDER_API(CFolderUtils, History)
IMPLEMENT_FOLDER_API(CFolderUtils, System)
IMPLEMENT_FOLDER_API(CFolderUtils, SystemX86)
IMPLEMENT_FOLDER_API(CFolderUtils, Windows)
IMPLEMENT_FOLDER_API(CFolderUtils, Profile)
IMPLEMENT_FOLDER_API(CFolderUtils, Pictures)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFilesX86)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFilesCommonX86)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFilesX64)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFilesCommonX64)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFiles)
IMPLEMENT_FOLDER_API(CFolderUtils, ProgramFilesCommon)
IMPLEMENT_FOLDER_API(CFolderUtils, UserProgramFiles)
IMPLEMENT_FOLDER_API(CFolderUtils, UserProgramFilesCommon)
IMPLEMENT_FOLDER_API(CFolderUtils, AdminTools)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonAdminTools)
IMPLEMENT_FOLDER_API(CFolderUtils, Music)
IMPLEMENT_FOLDER_API(CFolderUtils, Videos)
IMPLEMENT_FOLDER_API(CFolderUtils, Ringtones)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicPictures)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicMusic)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicVideos)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicRingtones)
IMPLEMENT_FOLDER_API(CFolderUtils, ResourceDir)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalizedResourcesDir)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonOEMLinks)
IMPLEMENT_FOLDER_API(CFolderUtils, CDBurning)
IMPLEMENT_FOLDER_API(CFolderUtils, UserProfiles)
IMPLEMENT_FOLDER_API(CFolderUtils, Playlists)
IMPLEMENT_FOLDER_API(CFolderUtils, SamplePlaylists)
IMPLEMENT_FOLDER_API(CFolderUtils, SampleMusic)
IMPLEMENT_FOLDER_API(CFolderUtils, SamplePictures)
IMPLEMENT_FOLDER_API(CFolderUtils, SampleVideos)
IMPLEMENT_FOLDER_API(CFolderUtils, PhotoAlbums)
IMPLEMENT_FOLDER_API(CFolderUtils, Public)
IMPLEMENT_FOLDER_API(CFolderUtils, ChangeRemovePrograms)
IMPLEMENT_FOLDER_API(CFolderUtils, AppUpdates)
IMPLEMENT_FOLDER_API(CFolderUtils, AddNewPrograms)
IMPLEMENT_FOLDER_API(CFolderUtils, Downloads)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicDownloads)
IMPLEMENT_FOLDER_API(CFolderUtils, SavedSearches)
IMPLEMENT_FOLDER_API(CFolderUtils, QuickLaunch)
IMPLEMENT_FOLDER_API(CFolderUtils, Contacts)
IMPLEMENT_FOLDER_API(CFolderUtils, SidebarParts)
IMPLEMENT_FOLDER_API(CFolderUtils, SidebarDefaultParts)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicGameTasks)
IMPLEMENT_FOLDER_API(CFolderUtils, GameTasks)
IMPLEMENT_FOLDER_API(CFolderUtils, SavedGames)
IMPLEMENT_FOLDER_API(CFolderUtils, Games)
IMPLEMENT_FOLDER_API(CFolderUtils, SEARCH_MAPI)
IMPLEMENT_FOLDER_API(CFolderUtils, SEARCH_CSC)
IMPLEMENT_FOLDER_API(CFolderUtils, Links)
IMPLEMENT_FOLDER_API(CFolderUtils, UsersFiles)
IMPLEMENT_FOLDER_API(CFolderUtils, UsersLibraries)
IMPLEMENT_FOLDER_API(CFolderUtils, SearchHome)
IMPLEMENT_FOLDER_API(CFolderUtils, OriginalImages)
IMPLEMENT_FOLDER_API(CFolderUtils, DocumentsLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, MusicLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, PicturesLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, VideosLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, RecordedTVLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, HomeGroup)
IMPLEMENT_FOLDER_API(CFolderUtils, HomeGroupCurrentUser)
IMPLEMENT_FOLDER_API(CFolderUtils, DeviceMetadataStore)
IMPLEMENT_FOLDER_API(CFolderUtils, Libraries)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicLibraries)
IMPLEMENT_FOLDER_API(CFolderUtils, UserPinned)
IMPLEMENT_FOLDER_API(CFolderUtils, ImplicitAppShortcuts)
IMPLEMENT_FOLDER_API(CFolderUtils, AccountPictures)
IMPLEMENT_FOLDER_API(CFolderUtils, PublicUserTiles)
IMPLEMENT_FOLDER_API(CFolderUtils, AppsFolder)
IMPLEMENT_FOLDER_API(CFolderUtils, StartMenuAllPrograms)
IMPLEMENT_FOLDER_API(CFolderUtils, CommonStartMenuPlaces)
IMPLEMENT_FOLDER_API(CFolderUtils, ApplicationShortcuts)
IMPLEMENT_FOLDER_API(CFolderUtils, RoamingTiles)
IMPLEMENT_FOLDER_API(CFolderUtils, RoamedTileImages)
IMPLEMENT_FOLDER_API(CFolderUtils, Screenshots)
IMPLEMENT_FOLDER_API(CFolderUtils, CameraRoll)
IMPLEMENT_FOLDER_API(CFolderUtils, SkyDrive)
IMPLEMENT_FOLDER_API(CFolderUtils, OneDrive)
IMPLEMENT_FOLDER_API(CFolderUtils, SkyDriveDocuments)
IMPLEMENT_FOLDER_API(CFolderUtils, SkyDrivePictures)
IMPLEMENT_FOLDER_API(CFolderUtils, SkyDriveMusic)
IMPLEMENT_FOLDER_API(CFolderUtils, SkyDriveCameraRoll)
IMPLEMENT_FOLDER_API(CFolderUtils, SearchHistory)
IMPLEMENT_FOLDER_API(CFolderUtils, SearchTemplates)
IMPLEMENT_FOLDER_API(CFolderUtils, CameraRollLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, SavedPictures)
IMPLEMENT_FOLDER_API(CFolderUtils, SavedPicturesLibrary)
IMPLEMENT_FOLDER_API(CFolderUtils, RetailDemo)
IMPLEMENT_FOLDER_API(CFolderUtils, Device)
IMPLEMENT_FOLDER_API(CFolderUtils, DevelopmentFiles)
IMPLEMENT_FOLDER_API(CFolderUtils, Objects3D)
IMPLEMENT_FOLDER_API(CFolderUtils, AppCaptures)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalDocuments)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalPictures)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalVideos)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalMusic)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalDownloads)
IMPLEMENT_FOLDER_API(CFolderUtils, RecordedCalls)
IMPLEMENT_FOLDER_API(CFolderUtils, AllAppMods)
IMPLEMENT_FOLDER_API(CFolderUtils, CurrentAppMods)
IMPLEMENT_FOLDER_API(CFolderUtils, AppDataDesktop)
IMPLEMENT_FOLDER_API(CFolderUtils, AppDataDocuments)
IMPLEMENT_FOLDER_API(CFolderUtils, AppDataFavorites)
IMPLEMENT_FOLDER_API(CFolderUtils, AppDataProgramData)
IMPLEMENT_FOLDER_API(CFolderUtils, LocalStorage)